package cn.codeinn.generator.controller;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.codeinn.generator.entity.Table;
import cn.codeinn.generator.service.IGeneratorService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "自动生成服务")
@RestController
@RequestMapping
public class GenController {

	@Autowired
	private IGeneratorService generatorService;

	@ApiOperation(value = "自动生成基础类")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "微服务包", name = "modelname", required = true, paramType = "path", dataType = "String"),
			@ApiImplicitParam(value = "表名", name = "tablename", required = true, paramType = "path", dataType = "String") })
	@GetMapping(value = "/generator/{modelname}/{tablename}")
	public void doGen(@PathVariable("modelname") String modelname, @PathVariable("tablename") String tablename) {
		Table t = new Table();
		t.setTables(new ArrayList<>());
		t.getTables().add(tablename);
		generatorService.generatorCode(t, modelname);
	}
}
